<?php

/*
 * rpc.php
 *
 * Responsible to handle all rpc requests comming from clients.
 * For calling a method, we use a path like /core/Auth/logout:
 * - core/Auth : use to find service filename path and service name
 *   -> service filename: core/auth_service.php
 *   -> service name: AuthService
 * - logout: use to find method name
 * Arguments can be passed using syntax a0=blah & a1=toto & a2[]=boudiou & a2[]=pof
 *
 * The whole url would look like:
 * http://blah.com/backend/rpc.php ? p=/core/Auth/logout & a1=toto & a2[]=boudiou & a2[]=pof
 */

require_once( 'core/core.php' );
require_once( 'core/service_caller.php' );

if( !isset( $_REQUEST['p'] ) ) error( 'Service path argument not set' );

// retreive arguments
$args = array();
$n = 0;
while( isset( $_REQUEST['a'.$n] ) )
{
	array_push( $args, $_REQUEST['a'.$n] );
	$n++;
}

$h = new ServiceCaller();

if( !$h->parse( $_REQUEST['p'] ) )
{
	error();
}
else
{
	$r = $h->call( $args );
}

output( getErrors(), $r );


?>
